package com.devfest.wishmaster.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable
public class Comment {

	@DatabaseField(id = true)
	private int id;

	@DatabaseField(dataType = DataType.DATE, canBeNull = true)
	private Date datecreated;

	@DatabaseField
	private String user;

	@DatabaseField
	private String text;

	@DatabaseField(foreign = true, foreignAutoRefresh = true)
	private WishItem wishItem;

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the datecreated
	 */
	public Date getDatecreated() {
		return datecreated;
	}

	/**
	 * @param datecreated
	 *            the datecreated to set
	 */
	public void setDatecreated(String datecreated) {
		if (datecreated.equals("")) {
			this.datecreated = new Date(0);
			return;
		}
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		while (!datecreated.endsWith("00")) {
			datecreated += "0";
		}
		try {
			this.datecreated = formatter.parse(datecreated.trim());
		} catch (ParseException e) {
		}
	}

	/**
	 * @return the user
	 */
	public String getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public void setUser(String user) {
		this.user = user;
	}

	/**
	 * @return the text
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param text
	 *            the text to set
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * @return the wishItem
	 */
	public WishItem getWishItem() {
		return wishItem;
	}

	/**
	 * @param wishItem
	 *            the wishItem to set
	 */
	public void setWishItem(WishItem wishItem) {
		this.wishItem = wishItem;
	}
}